package org.xiyinjihe.platform.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;


/**
 * 公共资源交易中心通知定时任务
 * Created by AnthonyPark
 */
@Configurable
@Component
@EnableScheduling
public class SubmitTask {

//    @Autowired
//    private PolicyInfoService policyInfoService;
//    @Autowired
//    private PolicyAlertService policyAlertService;
//
//    final static String EXPIRED = "1";
//    final static String CLAIM = "0";

    private Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * 预警生成
     */
    @Scheduled(cron = "0 0 3 * * ? ")
    public void payNotice() throws Exception {

//        logger.info("=======预警批处理开始=======");
//        //获取所有需要生成预警信息的列表
//        List<PolicyInfo> preprocessList = policyInfoService.getBatDataList(YesOrNo.NO.getValue());
//        if(preprocessList==null && preprocessList.size() <= 0){
//            logger.info("====没有要跑批的数据====");
//        }
//        for (PolicyInfo policyInfo:preprocessList) {
//            //循环判断单个订单
//            //保单结束日期
//            Date endDate = DateUtil.toShortDate(policyInfo.getDateEnd());
//            //当前日期
//            Date now =  DateUtil.toShortDate(new Date());
//            //30天后过期订单
//            int countDays = DateUtil.daysBetween(new Date(),policyInfo.getDateEnd());
//            //过期的订单
//            if (countDays < 0){
//                List<PolicyInfo> countData = policyInfoService.getRecordByApltName(policyInfo.getApltName());
//                if (countData!=null && countData.size() > 1){
//                    for (int i = 0; i < countData.size(); i++) {
//                        if (i!=0){
//                            policyInfoService.updateOffAlert(countData.get(i).getId());
//                            logger.info("====关闭已过期订单====");
//                        }
//                    }
//                }else {
//                    logger.info("====投保人没有续单====");
//                }
//                PolicyAlert alert = new PolicyAlert();
//                alert.setAlertDate(now);
//                alert.setAlertType(EXPIRED);
//                alert.setPolicyId(policyInfo.getId());
//                alert.setIsDelete(YesOrNo.NO.getValue());
//                Integer i = policyAlertService.insert(alert);
//                if (i > 0){
//                    logger.info("===新增过期预警成功=====");
//                }
//            }else if (countDays <=30){
//                    PolicyAlert alert = new PolicyAlert();
//                    alert.setAlertDate(now);
//                    alert.setAlertType(EXPIRED);
//                    alert.setPolicyId(policyInfo.getId());
//                    alert.setIsDelete(YesOrNo.NO.getValue());
//                    Integer i = policyAlertService.insert(alert);
//                    if (i > 0){
//                        logger.info("===新增即将过期预警成功=====");
//                    }
//                }
//        }
    }
}
